using Godot;
using Godot.Collections;
using System;

public partial class scp173 : Characters
{
	private Marker2D _hitboxPosition;
    private Area2D _hurtbox;
    //private Sight _sight;
    private Area2D sighted;
    private BehaviorTree _behaviorTree;
    public Array<string> sightFrom = new Array<string>();
	public override void Initialize()
    {
        base.Initialize();
        _hitboxPosition = GetNode<Marker2D>("Hitposition");
        _hurtbox = GetNode<Area2D>("Hurtbox");
        sighted = GetNode<Area2D>("sighted");
        sighted.AreaEntered += GetBody;
        sighted.AreaExited += RemoveBody;
        _behaviorTree = GetNode<BehaviorTree>("BehaviorTree");
    }
    

	public void GetBody(Node body)
    {
        if (body.Owner is Characters)
        {
            sightFrom.Add(body.Owner.Name);
            //GD.Print("被看见",body.Owner.Name);
            (this._characterData as EnemyData).target = body.Owner.Name;
            //_behaviorTree._Ready();
        }
    }
    public void RemoveBody(Node body)
    {
        if(body.Owner is Characters)
        {
            sightFrom.Remove(body.Owner.Name);
        }
    }

    public override void AimTarget()
    {
        Characters targetCharacter = GetTree().CurrentScene.GetNode<Characters>("%"+(_characterData as EnemyData).target);
		var scale = Math.PI*1.5 - targetCharacter._sight.Rotation;
		targetPos = targetCharacter.GlobalPosition + new Vector2((float)Math.Sin(scale)*30, (float)Math.Cos(scale)*30);
    }


}
